<?php
class tournament extends Model {
	private $_Class;
	private $_Surface;
	private $_Name;
	private $_Place;
	private $_Description;
	private $_InitialDate;
	private $_FinalDate;
	private $_Image;
	private $_Url;
	private $_Link;
	private $_Sex;
	private $_Points;
	private $_Fixture;
	
	private function _setDefaultValues($arrInitialValues = null){
		if (isset($arrInitialValues['points']) && !empty($arrInitialValues['points']))
			$this->setPoints($arrInitialValues['points']);
		else 
			$this->setPoints(0);
		
		if (isset($arrInitialValues['sex']) && !empty($arrInitialValues['sex']))
			$this->setSex($arrInitialValues['sex']);
		else 
			$this->setSex('');
		
		if (isset($arrInitialValues['link']) && !empty($arrInitialValues['link']))
			$this->setLink($arrInitialValues['link']);
		else 
			$this->setLink('');

		if (isset($arrInitialValues['image']) && !empty($arrInitialValues['image']))
			$this->setImage($arrInitialValues['image']);
		else 
			$this->setImage('');
		
		if (isset($arrInitialValues['final_date']) && !empty($arrInitialValues['final_date']))
			$this->setFinalDate($arrInitialValues['final_date']);
		else 
			$this->setFinalDate('');
		
		if (isset($arrInitialValues['initial_date']) && !empty($arrInitialValues['initial_date']))
			$this->setInitialDate($arrInitialValues['initial_date']);
		else 
			$this->setInitialDate('');
		
		if (isset($arrInitialValues['place']) && !empty($arrInitialValues['place']))
			$this->setPlace($arrInitialValues['place']);
		else 
			$this->setPlace('');
		
		if (isset($arrInitialValues['description']) && !empty($arrInitialValues['description']))
			$this->setDescription($arrInitialValues['description']);
		else 
			$this->setDescription('');
			
		if (isset($arrInitialValues['class']) && !empty($arrInitialValues['class']))
			$this->setClass($arrInitialValues['class']);
		else 
			$this->setClass(new tournament_class());

		if (isset($arrInitialValues['surface']) && !empty($arrInitialValues['surface']))
			$this->setSurface($arrInitialValues['surface']);
		else 
			$this->setSurface('');
			
		if (isset($arrInitialValues['name']) && !empty($arrInitialValues['name'])) {
			$this->setName($arrInitialValues['name']);
			$url = preg_replace('/["\',.:]/', '', FunctionsHelper::ReplaceAccentsAndEnie($arrInitialValues['name']));
			$this->setUrl(preg_replace('/[^a-zA-Z0-9]/', '-', $url));
		} else {
			$this->setName('');
		}
	}
	
	public function __construct($arrInitialValues = null){
		$this->setTable('tournament');
		$this->setColumnId('tournament_id');

		$this->_setDefaultValues($arrInitialValues);
		parent::__construct($arrInitialValues);
	}


	public function getUrl() {
		return $this->_Url;
	}

	public function setUrl($_Url) {
		$this->_Url = $_Url;
	}

	public function setFixture($value){
		$this->_Fixture = $value;
	}
	
	public function getFixture(){
		return $this->_Fixture;
	}
	
	public function setPoints($value){
		$this->_Points = $value;
	}
	
	public function getPoints(){
		return $this->_Points;
	}
	
	public function setSex($value){
		$this->_Sex = $value;
	}
	
	public function getSex(){
		return $this->_Sex;
	}
	
	public function setLink($value){
		$this->_Link = $value;
	}
	
	public function getLink(){
		return $this->_Link;
	}
	
	public function setImage($value){
		$this->_Image = $value;
	}
	
	public function getImage(){
		return $this->_Image;
	}
	
	public function setFinalDate($value){
		$this->_FinalDate = $value;
	}
	
	public function getFinalDate(){
		return $this->_FinalDate;
	}
	
	public function setInitialDate($value){
		$this->_InitialDate = $value;
	}
	
	public function getInitialDate(){
		return $this->_InitialDate;
	}
	
	public function setDescription($value){
		$this->_Description = $value;
	}
	
	public function getDescription(){
		return $this->_Description;
	}
	
	public function setPlace($value){
		$this->_Place = $value;
	}
	
	public function getPlace(){
		return $this->_Place;
	}
	
	public function setName($value){
		$this->_Name = $value;
	}
	
	public function getName(){
		return $this->_Name;
	}

	public function setSurface($value){
		$this->_Surface = $value;
	}
	
	public function getSurface(){
		return $this->_Surface;
	}
	
	public function setClass($value){
		$this->_Class = $value;
	}
	
	public function getClass(){
		return $this->_Class;
	}

	public function getTournamentsFromClass(){
		$query = '
			SELECT *
			FROM tournament
			WHERE class_id = ' . $this->getClass()->getId();
		$sex = $this->getSex();
		if (!empty($sex))
			$query .= '
				AND sex = "' . $sex . '" ';
		$query .= '
				AND Active = 1
			ORDER BY ' . $this->getOrderBy();

		$dbHelper = new DBHelper($query);
		return $dbHelper->getResult();
	}
}

?>